package com.ycz.algorithm.utils.hash;

import com.ycz.algorithm.utils.linkedlist.ListNode;

import java.util.Arrays;

/**
 * @Description 常见的哈希函数
 * @ClassName CommonHashFunction
 * @Author yanchengzhi
 * @date 2024.12.17 20:18
 */
public class CommonHashFunction {

    public static void main(String[] args) {
        // 整数和布尔量的哈希值就是其本身
        int num = 3;
        int hashNum = Integer.hashCode(num);
        System.out.println("整数3的哈希值为：" + hashNum);
        boolean bool = true;
        int hashBool = Boolean.hashCode(bool);
        System.out.println("布尔值true的哈希值为：" + hashBool);
        double dec = 3.14159;
        int hashDec = Double.hashCode(dec);
        System.out.println("浮点数" + dec + "的哈希值为：" + hashDec);
        String str = "Hello 算法";
        int hashStr = str.hashCode();
        System.out.println("字符串" + str + "的哈希值为：" + hashStr);
        Object[] arr = {12836, "小哈"};
        int hashTup = Arrays.hashCode(arr);
        System.out.println("数组的哈希值为：" + hashTup);
        ListNode obj = new ListNode(0);
        int hashObj = obj.hashCode();
        System.out.println("节点的哈希值为：" + hashObj);
    }

}
